<style lang="scss">
  @import 'index';
</style>

<template>
  <div class="ga-container">
    <div class="ga-distribution-apply" :hidden="activeindex != 0">
      <div class="banner">
        <img mode="widthFix" src="http://ga-1255639017.file.myqcloud.com/images/distribution/d_banner.png" alt="">
      </div>

      <div class="wrap">
        <h1>
          <span>欢迎申请成为</span>
          <span class="span2 gOrange">菓啊智慧新零售</span>
          <span>分销商</span>
        </h1>
        <h2 class="mt20">请填写申请信息：</h2>

        <form @submit="testSubmit" report-submit="true">
          <div class="ga-input-group mt20">
            <div class="input-group">
              <input type="text" class="form-control" v-model="nickname" placeholder="姓名" />
            </div>
          </div>
          <div class="ga-input-group mt20">
            <div class="input-group">
              <input type="text" class="form-control" v-model="mobile" placeholder="电话" />
            </div>
          </div>
          <div class="ga-input-group mt20">
            <div class="input-group">
              <input type="text" class="form-control" v-model="wxcode" placeholder="请填写微信号" />
            </div>
          </div>

          <div class="btn-box">
            <button formType="submit" class="btn primary">申请成为分销商</button>
          </div>
        </form>
      </div>

    </div>
    <div class="ga-msg" :hidden="activeindex != 1">
      <div class="iconImg">
        <img src="http://ga-1255639017.file.myqcloud.com/images/icon/suc.png" alt="">
      </div>
      <!--等待审核-->
      <p class="p">您的分销申请已经提交，请等待审核！</p>
      <a class="btn primary" @click="bindSwitchTab('../home/main')">去商城逛逛</a>

      <!--审核通过-->
      <!--<p class="p">您的分销申请已经审核通过！</p>-->
    </div>
    <div class="ga-msg" :hidden="activeindex != 2">
      <div class="iconImg">
        <img src="http://ga-1255639017.file.myqcloud.com/images/icon/suc.png" alt="">
      </div>
      <!--审核通过-->
      <p class="p">您的分销申请已经审核通过！</p>
    </div>
  </div>

</template>

<script>
import {isLogin} from '@/utils/handleLogin'
export default {
  data () {
    return {
       nickname: '',
       mobile: '',
       wxcode: '',
       activeindex: 0,
    }
  },
  methods: {
      async testSubmit (e) {
      if(this.activeindex != 0){
        return false
      }
      let params = {
         name: this.nickname,
         tel: this.mobile,
         wechat: this.wxcode,
      }
      this.$_util.ajax.post('https://guo-a.com/mapi/user/apply_distrib?token=' + this.$store.state.Token,params).then((res) => {
         if(res.code === 200){
           this.activeindex = 1
         }
      })
     },
     async load () {
      this.$_util.ajax.post('https://guo-a.com/mapi/user/isapplydistrib?token=' + this.$store.state.Token).then((res) => {
         console.log(res)
         if(res.code === 200){
            this.activeindex = res.isSet
         }
      })
     },
     /**
      * 路由跳转
      */
      bindNavigateTo (url) {
          wx.navigateTo({
            url
          })
      },
      bindSwitchTab (url) {
          wx.switchTab({
            url
          })
      },
  },
  created () {

  },
  onShow () {
    this.nickname = ''
    this.mobile = ''
    this.wxcode = ''
    isLogin(() => {
      this.load()
    })
  }
}
</script>
